import {action, observable, toJS} from 'mobx';
import * as EnableProcessInterventionApi from "../apis/EnableProcessInterventionApi";
import base from './../util/base';
import {getComsMobx} from "../util/convert";

export  class EnableProcessInterventionStore{
    @observable initialDatas = [];
    constructor() {
        this.getDetailInfo = this.getDetailInfo.bind(this);
        this.saveUpdateInfo = this.saveUpdateInfo.bind(this);
        this.updateInitialDatas = this.updateInitialDatas.bind(this);
    }

    @action getDetailInfo() {
        let {baseParam={}} = base.globalStore;
        const {requestid} = toJS(baseParam);
        let params = {requestid:requestid};
        EnableProcessInterventionApi.getDetailInfo(params).then(data => {
            this.initialDatas = data.data;

        });
        return this;
    }

    @action saveUpdateInfo(){
        let {baseParam={}} = base.globalStore;
        const params = {...baseParam};
        let sign = 0;
        toJS(this.initialDatas).map(c =>{
            let selectid = c.selectid;
            if(selectid=="1"){
                sign = 1;
            }
        })
        if(sign==0){
            WfForm.showMessage("请至少选择一条数据进行干预!");
            return false;
        }
        EnableProcessInterventionApi.SaveSubmitInfo({"editdatas":JSON.stringify(toJS(this.initialDatas)),...params}).then(data =>{
            WfForm.reloadPage();
        });
    }
    @action updateInitialDatas=(params) => {
        this.initialDatas = params;
    }
}
